<template>
    <div class="trade_bottom">
      <div class="m_strategy">
        <div class="ms_buy">
          <div class="ms_1">
            <Dropdown @on-click="strategy_select">
              <label class="lb_1">
                {{strategy_type}}
                <Icon type="ios-arrow-down"></Icon>
              </label>
              <DropdownMenu slot="list">
                <DropdownItem :name=item.name v-for="(item,strategy_type_key) in strategy_type_list" :key="strategy_type_key">{{item.name}}</DropdownItem>
              </DropdownMenu>
            </Dropdown>
            <label class="lb_2" v-if="run_status">({{list_strategy_run.length}}条)</label>
            <label class="lb_2" v-if="!run_status">({{list_strategy_unrun.length}}条)</label>
          </div>
          <div class="group_item"  v-for="(item ,index) in strategy_group_run" :key="index"  @click="strategy_choosely_run(index,item)" v-if="index<2 && run_status" >
            <a :class="{system_choseNav:item.selectCount>0}">{{item.group}} ({{item.selectCount}}/{{item.count}})</a>
          </div>

          <div class="group_item"  v-for="(item ,index) in strategy_group_unrun" :key="index"  @click="strategy_choosely_unrun(index,item)" v-if="index<2  && !run_status">
            <a :class="{system_choseNav:item.selectCount>0}">{{item.group}} ({{item.selectCount}}/{{item.count}})</a>
          </div>
        </div>
        <div class="ms_sell">
          <div class="group_item"  v-for="(item ,index) in strategy_group_run" :key="index"  @click="strategy_choosely_run(index,item)" v-if="index>=2 && run_status" >
            <a :class="{system_choseNav:item.selectCount>0}">{{item.group}} ({{item.selectCount}}/{{item.count}})</a>
          </div>

          <div class="group_item"  v-for="(item ,index) in strategy_group_unrun" :key="index"  @click="strategy_choosely_unrun(index,item)" v-if="index>=2 && !run_status">
            <a :class="{system_choseNav:item.selectCount>0}">{{item.group}} ({{item.selectCount}}/{{item.count}})</a>
          </div>
          <div class="ms_other">
            <Checkbox class="checkcolor" @on-change="check_run()">未启动策略</Checkbox>
            <Button  type="primary" @click="delete_modall =true" v-if="!run_status && unrun_select_Ids.length===0">一键删除</Button>
            <Button  type="primary" @click="delete_modall =true" v-if="!run_status && unrun_select_Ids.length!==0">选中删除</Button>
            <Button  type="primary" @click="run_status_modall = true" v-if="!run_status && unrun_select_Ids.length===0">一键启动</Button>
            <Button  type="primary" @click="run_status_modall = true" v-if="!run_status && unrun_select_Ids.length!==0">选中启动</Button>
          </div>
        </div>
      </div>
      <div class="m_group">
        <run_group_select v-if="run_status"></run_group_select>
        <unrun_group_select v-else></unrun_group_select>
      </div>
      <div class="m_table">
        <div class="run_strategy_table" v-show=run_status>
          <ux-grid
            :border =false
            ref="strategy_Table_run"
            :data="list_strategy_run"
            :height="strategy_height"
            border = false
            :stripe="true"
            show-header-overflow="title"
            :cell-style="cellStyle"
            @selection-change="runSelectList"
            @filter-change="filterChange_group"
            @header-click="headerClick_group"
            >
            <ux-table-column type="checkbox" width="80" align="center" fixed="left"/>
            <ux-table-column type="index" width="80" align="center" fixed="left"/>
            <ux-table-column field= "group_id" title="策略分组" width= "160" align="center" fixed="left"
            :filters="[]"
            />
            <ux-table-column field= "direction" title="方向" width= "160" align="center" fixed="left"/>
            <ux-table-column field= "display_inposition_volume" title="仓位" width= "160" align="center" fixed="left"/>
            <ux-table-column field= "display_amount_cycle_stop_amount_cycle" title="循环次数" width= "160" align="center" fixed="left"/>
            <ux-table-column field= "open" title="开仓价格" width= "160" align="center" fixed="left"/>
            <ux-table-column field= "close" title="平仓价格" width= "160" align="center" fixed="left"/>
            <ux-table-column field= "points_translation" title="平移点数" width= "160" align="center"/>
            <ux-table-column field= "points_translation_time" title="平移时间" width= "180" align="center"/>
            <ux-table-column field= "stop_loss" title="止损价格" width= "160" align="center"/>
            <ux-table-column field= "stop_loss_type" title="止损平仓方式" width= "160" align="center"/>
            <ux-table-column field= "stop_loss_price_type" title="止损价格类型" width= "160" align="center"/>
            <ux-table-column field= "stop_profit" title="止盈价格" width= "160" align="center"/>
            <ux-table-column field= "stop_profit_type" title="止盈平仓方式" width= "160" align="center"/>
            <ux-table-column field= "stop_profit_price_type" title="止盈价格类型" width= "160" align="center"/>
            <ux-table-column field= "strategy_status" title="状态" width= "160" align="center"/>
            <ux-table-column field= "create_time" title="创建时间" width= "180" align="center"/>
            <ux-table-column field= "stop_time_type" title="触发时间平仓方式" width= "160" align="center"/>
            <ux-table-column field= "stop_len" title="运行时长" width= "160" align="center"/>
            <ux-table-column field= "stop_time" title="终止时间" width= "180" align="center"/>
            <ux-table-column field= "strategy_id" title="策略ID" width= "160" align="center"/>
          </ux-grid>
        </div>
        <div class="unrun_strategy_table" v-show=!run_status>
          <ux-grid
            :border =false
            ref="strategy_Table_unrun"
            :data="list_strategy_unrun"
            :height="strategy_height"
            border = false
            :stripe="true"
            show-header-overflow="title"
            :cell-style="cellStyle"
            @selection-change="unrunSelectList"
            @filter-change="unfilterChange_group"
            @header-click="unheaderClick_group">
            <ux-table-column type="checkbox" width="80" align="center" fixed="left"/>
            <ux-table-column type="index" width="80" align="center" fixed="left"/>
            <ux-table-column field= "group_id" title="策略分组" width= "160" align="center" fixed="left"
                             :filters="[]"/>
            <ux-table-column field= "direction" title="方向" width= "160" align="center" fixed="left"/>
            <ux-table-column field= "display_inposition_volume" title="仓位" width= "160" align="center" fixed="left"/>
            <ux-table-column field= "display_amount_cycle_stop_amount_cycle" title="循环次数" width= "160" align="center" fixed="left"/>
            <ux-table-column field= "open" title="开仓价格" width= "160" align="center" fixed="left"/>
            <ux-table-column field= "close" title="平仓价格" width= "160" align="center" fixed="left"/>
            <ux-table-column field= "points_translation" title="平移点数" width= "160" align="center"/>
            <ux-table-column field= "points_translation_time" title="平移时间" width= "180" align="center"/>
            <ux-table-column field= "stop_loss" title="止损价格" width= "160" align="center"/>
            <ux-table-column field= "stop_loss_type" title="止损平仓方式" width= "160" align="center"/>
            <ux-table-column field= "stop_loss_price_type" title="止损价格类型" width= "160" align="center"/>
            <ux-table-column field= "stop_profit" title="止盈价格" width= "160" align="center"/>
            <ux-table-column field= "stop_profit_type" title="止盈平仓方式" width= "160" align="center"/>
            <ux-table-column field= "stop_profit_price_type" title="止盈价格类型" width= "160" align="center"/>
            <ux-table-column field= "strategy_status" title="状态" width= "160" align="center"/>
            <ux-table-column field= "create_time" title="创建时间" width= "180" align="center"/>
            <ux-table-column field= "stop_time_type" title="触发时间平仓方式" width= "160" align="center"/>
            <ux-table-column field= "stop_len" title="运行时间" width= "160" align="center"/>
            <ux-table-column field= "stop_time" title="终止时间" width= "180" align="center"/>
            <ux-table-column field= "strategy_id" title="策略ID" width= "160" align="center"/>
          </ux-grid>
        </div>
      </div>
      <div class="bottom_modal">
        <Modal
          v-model="delete_modall"
          ok-text="确定"
          cancel-text="取消"
          :mask-closable = "false"
          :loading ='true'
          @on-ok="deleteStrategy()">
          <p>确定要删除吗？</p>
        </Modal>
        <Modal
          v-model="run_status_modall"
          ok-text="确定"
          cancel-text="取消"
          :mask-closable = "false"
          :loading ='true'
          @on-ok="starttrategy()">
          <p>确认启动吗？</p>
        </Modal>
      </div>
    </div>
</template>

<script>
  import {
    deleteStrategy,
    startStrategy,
    translationAll,
    updateStrategy,
    updateStrategyBatch,
  } from '@/api/trade'
  import { mapGetters,mapMutations,mapActions } from 'vuex'
  import Run_group_select from "../run_group_select/run_group_select";
  import Unrun_group_select from "../unrun_group_select/unrun_group_select";
    export default {
        name: "trade_bottom",
      components: {Unrun_group_select, Run_group_select},
      data(){
        return{
          list_strategy:[], //当前用户全部量化策略
          list_strategy_run:[], //当前用户启动量化策略
          list_strategy_unrun:[], //当前用户未启动量化策略
          data_group_id_run:[],//启动策略组别
          data_group_id_unrun:[],//未启动策略组别
          contractSelected: '',
          clientSelected: '',
          Interval_getListStrategy:'',
          strategy_type_list:[
            {
              name:'循环策略'
            },
            {
              name:'关联策略'
            },
            {
              name:'网络策略'
            },
            {
              name:'阶梯策略'
            },
            {
              name:'顺势加仓策略'
            },
            {
              name:'追踪止盈止损策略'
            },
            {
              name:'市场浮动策略'
            },
          ],
          strategy_type:'循环策略',
          strategy_group_run:[
            {
              group:'多单-已持仓',
              count:0,
              selectCount:0,
            },
            {
              group:'多单-未持仓',
              count:0,
              selectCount:0,
            },
            {
              group:'空单-已持仓',
              count:0,
              selectCount:0,
            },
            {
              group:'空单-未持仓',
              count:0,
              selectCount:0,
            },
          ],
          strategy_group_unrun:[
            {
              group:'多单-已持仓',
              count:0,
              selectCount:0,
            },
            {
              group:'多单-未持仓',
              count:0,
              selectCount:0,
            },
            {
              group:'空单-已持仓',
              count:0,
              selectCount:0,
            },
            {
              group:'空单-未持仓',
              count:0,
              selectCount:0,
            },
          ],
          run_status:true,
          run_select_Ids:[],//启动的选中的数组
          unrun_select_Ids:[],//没启动的选中的数组
          delete_modall:false,
          run_status_modall:false,
          strategy_columns:[
            {
              label: '策略分组',
              width: 120,
              prop: 'group_id'
            },
            {
              label: '策略类型',
              width: 85,
              prop: 'strategy_type'
            },
            {
              label: '方向',
              width: 55,
              prop: 'direction',
            },
            {
              label: '仓位',
              width: 80,
              prop: 'display_inposition_volume'
            },
            {
              label: '循环次数',
              width: 80,
              prop: 'display_amount_cycle_stop_amount_cycle'
            },
            {
              label: '开仓价格',
              width: 95,
              prop: 'open',
            },
            {
              label: '平仓价格',
              width: 95,
              prop: 'close',
            },
            {
              label: '止损价格',
              width: 80,
              prop: 'stop_loss'
            },
            {
              label: '止损平仓方式',
              width: 110,
              prop: 'stop_loss_type'
            },
            {
              label: '止损价格类型',
              width: 110,
              prop: 'stop_loss_price_type'
            },
            {
              label: '止盈价格',
              width: 80,
              prop: 'stop_profit'
            },
            {
              label: '止盈平仓方式',
              width: 110,
              prop: 'stop_profit_type'
            },
            {
              label: '止盈价格类型',
              width: 110,
              prop: 'stop_profit_price_type'
            },
            {
              label: '平移点数',
              width: 80,
              prop: 'points_translation'
            },
            {
              label: '创建时间',
              width: 180,
              prop: 'create_time'
            },
            {
              label: '触发时间平仓方式',
              width: 140,
              prop: 'stop_time_type'
            },
            {
              label: '运行时间',
              width: 80,
              prop: 'stop_len'
            },
            {
              label: '终止时间',
              width: 160,
              prop: 'stop_time'
            },
            {
              label: '状态',
              width: 70,
              prop: 'strategy_status'
            },
          ],
          strategy_height:800,
          select_id_lock:false,
          filter_list_run:[],//策略分组数组
          filter_select_list_run:[],
          filter_flag:true,

          unselect_id_lock:false,
          filter_list_unrun:[],//策略分组数组
          filter_select_list_unrun:[],
          unfilter_flag:true,
        }
      },
      methods:{
        ...mapGetters([
          'get_list_strategy',
          'get_client',
          'get_contract',
          'get_run_select_Ids',
          'get_unrun_select_Ids',
          'get_select_id_lock',
          'get_list_strategy_run',
          'get_list_strategy_unrun',
          'get_data_group_id_run',
          'get_data_group_id_unrun',
        ]),
        ...mapMutations([
          'set_run_select_Ids',
          'set_unrun_select_Ids',
          'set_select_id_lock',
          'set_data_group_id_unrun',
          'set_data_group_id_run',
          'set_run_status',
        ]),
        ...mapActions([
          'getListStrategypro',
        ]),
        get_ListStrategy2(){
          let client = this.clientSelected; //用户ID（用户名）
          let contract = this.contractSelected;//合约名称
          this.getListStrategypro({client,contract}).then(res =>{
            console.log(res);
          }).catch(err =>{
            console.log(err)
          })
        },
        strategy_select(name){
          this.strategy_type = name;
        },
        check_run(){
          this.run_status = !this.run_status;
        },
        //策略分组选择
        strategy_choosely_run(n,item){
          let setObj = new Set(this.run_select_Ids);
          //如果没分组没全选就全勾上，全选了就全取消
          if(item.count != item.selectCount){
            if(item.group === '多单-未持仓'){
              this.list_strategy_run.forEach(
                (res) =>{
                  if(res.direction === '多' && Number(res.inposition) === 0){
                    setObj.add(res.strategy_id)
                  }
                })
            }else if(item.group === '多单-已持仓'){
              this.list_strategy_run.forEach(
                (res) =>{
                  if(res.direction === '多' && Number(res.inposition) !== 0){
                    setObj.add(res.strategy_id)
                  }
                })
            }else if(item.group === '空单-未持仓'){
              this.list_strategy_run.forEach(
                (res) =>{
                  if(res.direction === '空' && Number(res.inposition) === 0){
                    setObj.add(res.strategy_id)
                  }
                })
            }else if(item.group === '空单-已持仓'){
              this.list_strategy_run.forEach(
                (res) =>{
                  if(res.direction === '空' && Number(res.inposition) !== 0){
                    setObj.add(res.strategy_id)
                  }
                })
            }
          }else{
            if(item.group === '多单-未持仓'){
              this.list_strategy_run.forEach(
                (res) =>{
                  if(res.direction === '多' && Number(res.inposition) === 0){
                    setObj.delete(res.strategy_id)
                  }
                })
            }else if(item.group === '多单-已持仓'){
              this.list_strategy_run.forEach(
                (res) =>{
                  if(res.direction === '多' && Number(res.inposition) !== 0){
                    setObj.delete(res.strategy_id)
                  }
                })
            }else if(item.group === '空单-未持仓'){
              this.list_strategy_run.forEach(
                (res) =>{
                  if(res.direction === '空' && Number(res.inposition) === 0){
                    setObj.delete(res.strategy_id)
                  }
                })
            }else if(item.group === '空单-已持仓'){
              this.list_strategy_run.forEach(
                (res) =>{
                  if(res.direction === '空' && Number(res.inposition) !== 0){
                    setObj.delete(res.strategy_id)
                  }
                })
            }
          }
          // this.set_select_id_lock(true);//这里是告诉bottom不要再执行勾选事件
          this.run_select_Ids =Array.from(new Set(setObj));
          this.SelectionCount_run();
          this.set_run_select_Ids(this.run_select_Ids);
        },
        select_init_run(){
          if(this.run_select_Ids.length === 0){
            this.strategy_group_run = [
              {
                group:'多单-已持仓',
                count:0,
                selectCount:0,
              },
              {
                group:'多单-未持仓',
                count:0,
                selectCount:0,
              },
              {
                group:'空单-已持仓',
                count:0,
                selectCount:0,
              },
              {
                group:'空单-未持仓',
                count:0,
                selectCount:0,
              },
            ];//初始化
            this.list_strategy_run.forEach(
              (res) =>{
                if(res.direction === '多' && Number(res.inposition) !== 0){
                  this.strategy_group_run[0].count++;
                }
                if(res.direction === '多' && Number(res.inposition) === 0){
                  this.strategy_group_run[1].count++;
                }
                if(res.direction === '空' && Number(res.inposition) !== 0){
                  this.strategy_group_run[2].count++;
                }
                if(res.direction === '空' && Number(res.inposition) === 0){
                  this.strategy_group_run[3].count++;
                }
              }
            );
          }
        },
        //根据勾选id获取各分组勾选数量并亮起按钮
        SelectionCount_run(){
          var strategy_map =new Map();
          if(this.list_strategy_run.length>0 || this.run_select_Ids.length === 0){   //在已启动中查询
            this.list_strategy_run.forEach((row) =>{
              for(var i = 0; i<this.run_select_Ids.length;i++){
                if(row.strategy_id === this.run_select_Ids[i]){
                  if(!strategy_map.has(row.group_id_pro_2)){  //没有就初始化0
                    strategy_map.set(row.group_id_pro_2,0)
                  }
                  strategy_map.set(row.group_id_pro_2,strategy_map.get(row.group_id_pro_2)+1); //不管有没有都加一
                  break;
                }
              }
            });
            //遍历自定义分组，如果map里有自定义分组名字有对应的key，就设置为对应勾选数量
            this.strategy_group_run
              .map(
                function(current, index, array){
                  if(strategy_map.has(current.group)) {
                    current['selectCount'] = strategy_map.get(current.group);
                    return current
                  }else{
                    current['selectCount'] = 0;
                  }
                });
          }else {
            this.strategy_group_run
              .map(
                function(current, index, array){
                  current['selectCount'] =0;
                  return current
                });
          }
        },
        //策略分组选择
        strategy_choosely_unrun(n,item){
          let setObj = new Set(this.unrun_select_Ids);
          //如果没分组没全选就全勾上，全选了就全取消
          if(item.count != item.selectCount){
            if(item.group === '多单-未持仓'){
              this.list_strategy_unrun.forEach(
                (res) =>{
                  if(res.direction === '多' && Number(res.inposition) === 0){
                    setObj.add(res.strategy_id)
                  }
                })
            }else if(item.group === '多单-已持仓'){
              this.list_strategy_unrun.forEach(
                (res) =>{
                  if(res.direction === '多' && Number(res.inposition) !== 0){
                    setObj.add(res.strategy_id)
                  }
                })
            }else if(item.group === '空单-未持仓'){
              this.list_strategy_unrun.forEach(
                (res) =>{
                  if(res.direction === '空' && Number(res.inposition) === 0){
                    setObj.add(res.strategy_id)
                  }
                })
            }else if(item.group === '空单-已持仓'){
              this.list_strategy_unrun.forEach(
                (res) =>{
                  if(res.direction === '空' && Number(res.inposition) !== 0){
                    setObj.add(res.strategy_id)
                  }
                })
            }
          }else{
            if(item.group === '多单-未持仓'){
              this.list_strategy_unrun.forEach(
                (res) =>{
                  if(res.direction === '多' && Number(res.inposition) === 0){
                    setObj.delete(res.strategy_id)
                  }
                })
            }else if(item.group === '多单-已持仓'){
              this.list_strategy_unrun.forEach(
                (res) =>{
                  if(res.direction === '多' && Number(res.inposition) !== 0){
                    setObj.delete(res.strategy_id)
                  }
                })
            }else if(item.group === '空单-未持仓'){
              this.list_strategy_unrun.forEach(
                (res) =>{
                  if(res.direction === '空' && Number(res.inposition) === 0){
                    setObj.delete(res.strategy_id)
                  }
                })
            }else if(item.group === '空单-已持仓'){
              this.list_strategy_unrun.forEach(
                (res) =>{
                  if(res.direction === '空' && Number(res.inposition) !== 0){
                    setObj.delete(res.strategy_id)
                  }
                })
            }
          }
          // this.set_select_id_lock(true);//这里是告诉bottom不要再执行勾选事件
          this.unrun_select_Ids =Array.from(new Set(setObj));
          this.SelectionCount_unrun();
          this.set_unrun_select_Ids(this.unrun_select_Ids);
        },
        select_init_unrun(){
          if(this.unrun_select_Ids.length === 0){
            this.strategy_group_unrun = [
              {
                group:'多单-已持仓',
                count:0,
                selectCount:0,
              },
              {
                group:'多单-未持仓',
                count:0,
                selectCount:0,
              },
              {
                group:'空单-已持仓',
                count:0,
                selectCount:0,
              },
              {
                group:'空单-未持仓',
                count:0,
                selectCount:0,
              },
            ];//初始化
            this.list_strategy_unrun.forEach(
              (res) =>{
                if(res.direction === '多' && Number(res.inposition) !== 0){
                  this.strategy_group_unrun[0].count++;
                }
                if(res.direction === '多' && Number(res.inposition) === 0){
                  this.strategy_group_unrun[1].count++;
                }
                if(res.direction === '空' && Number(res.inposition) !== 0){
                  this.strategy_group_unrun[2].count++;
                }
                if(res.direction === '空' && Number(res.inposition) === 0){
                  this.strategy_group_unrun[3].count++;
                }
              }
            );
          }
        },
        //根据勾选id获取各分组勾选数量并亮起按钮
        SelectionCount_unrun(){
          var strategy_map =new Map();
          if(this.list_strategy_unrun.length>0 || this.unrun_select_Ids.length === 0){   //在已启动中查询
            this.list_strategy_unrun.forEach((row) =>{
              for(var i = 0; i<this.unrun_select_Ids.length;i++){
                if(row.strategy_id === this.unrun_select_Ids[i]){
                  if(!strategy_map.has(row.group_id_pro_2)){  //没有就初始化0
                    strategy_map.set(row.group_id_pro_2,0)
                  }
                  strategy_map.set(row.group_id_pro_2,strategy_map.get(row.group_id_pro_2)+1); //不管有没有都加一
                  break;
                }
              }
            });
            //遍历自定义分组，如果map里有自定义分组名字有对应的key，就设置为对应勾选数量
            this.strategy_group_unrun
              .map(
                function(current, index, array){
                  if(strategy_map.has(current.group)) {
                    current['selectCount'] = strategy_map.get(current.group);
                    return current
                  }else{
                    current['selectCount'] = 0;
                  }
                });
          }else {
            this.strategy_group_unrun
              .map(
                function(current, index, array){
                  current['selectCount'] =0;
                  return current
                });
          }
        },
        //修改颜色
        cellStyle(row,column,rowIndex,columnIndex){
          if(row.column.title==="方向" && row.row.direction =='多'){
            return 'color:#24C624'
          }else if(row.column.title==="方向" && row.row.direction =='空'){
            return 'color:#E13E7F'
          }
          if(row.column.title==="仓位" && Number(row.row.inposition) > 0 ){
            return 'color:#DD8A45'
          }
          if(row.column.title==="循环次数" ){
            return 'color:#F3C83A'
          }
          if(row.column.title==="平移点数" && Number(row.row.points_translation) > 0 ){
            return 'color:#76B4FF'
          }
        },
        //获取启动的选中行
        runSelectList(selection){
          if(!this.select_id_lock){
            let new_run_select_Ids = [];
            if(selection.length>0){
              for(let i=0; i<selection.length; i++){
                new_run_select_Ids.push(selection[i].strategy_id)
              }
              this.run_select_Ids = new_run_select_Ids;
            }else{
              this.run_select_Ids = []
            }
            this.set_run_select_Ids(this.run_select_Ids);
          }
        },
        //获取未启动的选中行
        unrunSelectList(selection){
          if(!this.select_id_lock){
            let new_unrun_select_Ids = [];
            if(selection.length>0){
              for(let i=0; i<selection.length; i++){
                new_unrun_select_Ids.push(selection[i].strategy_id)
              }
              this.unrun_select_Ids = new_unrun_select_Ids;
            }else{
              this.unrun_select_Ids = []
            }
            this.set_unrun_select_Ids(this.unrun_select_Ids);
          }
        },
        //默认选中
        defaultSelection(){
          if(this.list_strategy_run.length>0){
            this.list_strategy_run.forEach((row) =>{
              if(this.run_select_Ids.includes(row.strategy_id)){
                this.$refs.strategy_Table_run.toggleRowSelection([
                  {
                    row: row,
                    selected: true
                  }
                ]);
                return;
              }
            })
          }
          if(this.list_strategy_unrun.length>0){
            this.list_strategy_unrun.forEach((row) =>{
              if(this.unrun_select_Ids.includes(row.strategy_id)){
                this.$refs.strategy_Table_unrun.toggleRowSelection([
                  {
                    row: row,
                    selected: true
                  }
                ]);
                return;
              }
            })
          }
        },
        //已启动选中
        run_selection(){
          if(this.list_strategy_run.length>0){
            this.select_id_lock =true;
            this.$refs.strategy_Table_run.clearSelection();
            this.list_strategy_run.forEach((row) =>{
              for(let i =0; i<this.run_select_Ids.length;i++){
                if(row.strategy_id == this.run_select_Ids[i]){
                  this.$refs.strategy_Table_run.toggleRowSelection([
                    {
                      row: row
                    }
                  ])
                }
              }
            });
            this.select_id_lock =false;   //defined_gourp执行完后放开锁
            this.set_select_id_lock(this.select_id_lock);
          }
        },
        //未启动选中
        unrun_selection(){
          if(this.list_strategy_unrun.length>0){
            this.select_id_lock =true;
            this.$refs.strategy_Table_unrun.clearSelection();
            this.list_strategy_unrun.forEach((row) =>{
              for(let i =0; i<this.unrun_select_Ids.length;i++){
                if(row.strategy_id == this.unrun_select_Ids[i]){
                  this.$refs.strategy_Table_unrun.toggleRowSelection([
                    {
                      row: row
                    }
                  ])
                }
              }
            });
            this.select_id_lock =false;   //defined_gourp执行完后放开锁
            this.set_select_id_lock(this.select_id_lock);
          }
        },
        //勾选系统已启动分组
        select_strategy_run(){
          var strategy_map =new Map();
          if(this.list_strategy_run.length>0 || this.run_select_Ids.length === 0){   //在已启动中查询
            this.list_strategy_run.forEach((row) =>{
              for(var i = 0; i<this.run_select_Ids.length;i++){
                if(row.strategy_id === this.run_select_Ids[i]){
                  if(!strategy_map.has(row.group_id_pro_2)){  //没有就初始化0
                    strategy_map.set(row.group_id_pro_2,0)
                  }
                  strategy_map.set(row.group_id_pro_2,strategy_map.get(row.group_id_pro_2)+1); //不管有没有都加一
                  break;
                }
              }
            });
            this.strategy_group_run
              .map(
                function(current, index, array){
                  if(strategy_map.has(current.group)) {
                    current['selectCount'] = strategy_map.get(current.group);
                    return current
                  }else{
                    current['selectCount'] = 0;
                  }
                });
          }else {
            this.data_group_id_run
              .map(
                function(current, index, array){
                  current['selectCount'] =0;
                  return current
                });
            this.strategy_group_run
              .map(
                function(current, index, array){
                  current['selectCount'] =0;
                  return current
                });
          }
        },
        //勾选系统未启动分组
        select_strategy_unrun(){
          var strategy_map =new Map();
          if(this.list_strategy_unrun.length>0 || this.unrun_select_Ids.length === 0){   //在已启动中查询
            this.list_strategy_unrun.forEach((row) =>{
              for(var i = 0; i<this.unrun_select_Ids.length;i++){
                if(row.strategy_id === this.unrun_select_Ids[i]){
                  if(!strategy_map.has(row.group_id_pro_2)){  //没有就初始化0
                    strategy_map.set(row.group_id_pro_2,0)
                  }
                  strategy_map.set(row.group_id_pro_2,strategy_map.get(row.group_id_pro_2)+1); //不管有没有都加一
                  break;
                }
              }
            });
            this.strategy_group_unrun
              .map(
                function(current, index, array){
                  if(strategy_map.has(current.group)) {
                    current['selectCount'] = strategy_map.get(current.group);
                    return current
                  }else{
                    current['selectCount'] = 0;
                  }
                });
          }else {
            this.data_group_id_unrun
              .map(
                function(current, index, array){
                  current['selectCount'] =0;
                  return current
                });
            this.strategy_group_unrun
              .map(
                function(current, index, array){
                  current['selectCount'] =0;
                  return current
                });
          }
        },
        //启动策略
        starttrategy(){
          let params = {
            client:this.clientSelected,
            contract:this.contractSelected,
            start_list:this.unrun_select_Ids.join(",")
          };
          this.list_strategy_unrun = [];
          startStrategy(params).then(res=>{
            this.run_status_modall =false;
            if(res.status === 502){
              this.$Message.error("发生502，请核查启动策略");
              return;
            }
            if(res.data.code === 1000){
              this.$Message.success('启动成功');
              this.get_ListStrategy2();
            }
            this.run_select_Ids = [];
            this.unrun_select_Ids = [];
            this.set_run_select_Ids(this.run_select_Ids);
            this.set_unrun_select_Ids(this.unrun_select_Ids);
          }).catch(res=>{
            this.$Message.error("发生502，请核查启动策略");
            return;
          });
        },
        //删除策略
        deleteStrategy(){
          let params = {
            client:this.clientSelected,
            contract:this.contractSelected,
            delete_list:this.unrun_select_Ids.join(",")
          };
          this.list_strategy_unrun = [];
          deleteStrategy(params).then(res=>{
            this.delete_modall = false;
            if(res.status === 502){
              this.$Message.error("发生502，请核查删除策略");
              return;
            }
            if(res.data.code === 1000){
              this.$Message.success('删除成功');
              this.get_ListStrategy2();
            }
            this.run_select_Ids = [];
            this.unrun_select_Ids = [];
            this.set_run_select_Ids(this.run_select_Ids);
            this.set_unrun_select_Ids(this.unrun_select_Ids);
            this.set_data_group_id_unrun([])
          }).catch(res=>{
            this.$Message.error("发生502，请核查删除策略");
            return;
          });
        },
        //修改启动筛查
        updateRunGroup_idEvent(){
          if(this.filter_flag){
            const column = this.$refs.strategy_Table_run.getColumnByField('group_id');
            let group_id_run = this.get_data_group_id_run();
            let fillter_set = new Set();
            let filter_list = [];
            if(group_id_run.length!==0){
              for(let i = 0 ; i<group_id_run.length;i++){
                fillter_set.add(group_id_run[i].group.split('-')[0]);
              }
              for(let x of fillter_set){
                if(this.filter_select_list_run.includes(x)){
                  filter_list.push(
                    {
                      label:x,
                      value:x,
                      checked: true
                    }
                  )
                }else{
                  filter_list.push(
                    {
                      label:x,
                      value:x,
                    }
                  )
                }

              }
              this.filter_list_run = filter_list;
              // 修改筛选列表，并默认设置为选中状态
              this.$nextTick(function() {
                this.$refs.strategy_Table_run.setFilter(column, this.filter_list_run)
              });
            }else{
              this.filter_list_run = [];
              this.$nextTick(function() {
                this.$refs.strategy_Table_run.setFilter(column, [])
              });

            }
            // 修改条件之后，需要手动调用 updateData 处理表格数据
            this.$nextTick(function() {
              this.$refs.strategy_Table_run.updateData();
            });
          }
        },
        //修改启动筛查
        unupdateRunGroup_idEvent(){
          if(this.unfilter_flag){
            const column = this.$refs.strategy_Table_unrun.getColumnByField('group_id');
            let group_id_unrun = this.get_data_group_id_unrun();
            let fillter_set = new Set();
            let filter_list = [];
            if(group_id_unrun.length!==0){
              for(let i = 0 ; i<group_id_unrun.length;i++){
                fillter_set.add(group_id_unrun[i].group.split('-')[0]);
              }
              for(let x of fillter_set){
                if(this.filter_select_list_unrun.includes(x)){
                  filter_list.push(
                    {
                      label:x,
                      value:x,
                      checked: true
                    }
                  )
                }else{
                  filter_list.push(
                    {
                      label:x,
                      value:x,
                    }
                  )
                }

              }
              this.filter_list_unrun = filter_list;
              // 修改筛选列表，并默认设置为选中状态
              this.$nextTick(function() {
                this.$refs.strategy_Table_unrun.setFilter(column, this.filter_list_unrun)
              });
            }else{
              this.filter_list_unrun = [];
              this.$nextTick(function() {
                this.$refs.strategy_Table_unrun.setFilter(column, [])
              });

            }
            // 修改条件之后，需要手动调用 updateData 处理表格数据
            this.$nextTick(function() {
              this.$refs.strategy_Table_unrun.updateData();
            });
          }
        },
        filterChange_group({ column, property, values, datas, filters, $event }){
          this.filter_select_list_run = values;
          this.filter_flag = true;
        },
        //表头
        headerClick_group(column, event){
          if(column.property ==='group_id'){
            this.filter_flag = false;
          if(this.filter_list_run.length === 0 || this.get_data_group_id_run().length === 0){ //假刷新
              this.filter_flag = true;
              this.updateRunGroup_idEvent();
              this.filter_flag = false;
            }
          }
        },
        unfilterChange_group({ column, property, values, datas, filters, $event }){
          this.filter_select_list_unrun = values;
          this.unfilter_flag = true;
        },
        //表头
        unheaderClick_group(column, event){
          if(column.property ==='group_id'){
            this.unfilter_flag = false;
            if(this.filter_list_unrun.length === 0 || this.get_data_group_id_unrun().length === 0){ //假刷新
              this.unfilter_flag = true;
              this.unupdateRunGroup_idEvent();
              this.unfilter_flag = false;
            }
          }
        },

        updateData:function(){
          return this.handleTableData(!0)
            .then(this.updateFooter)
            .then(this.recalculate)
        },
      },
      created(){
        if(this.get_client() != ''){
          this.clientSelected = this.get_client();
        }else {
          this.clientSelected = '';
        }
        if( this.get_contract() != ''){
          this.contractSelected = this.get_contract();
        }else{
          this.contractSelected = '';
        }
        if( this.get_list_strategy_run() != ''){
          this.list_strategy_run = this.get_list_strategy_run();
          this.select_init_run();
        }else{
          this.list_strategy_run = [];
        }
        if( this.get_list_strategy_unrun() != ''){
          this.list_strategy_unrun = this.get_list_strategy_unrun();
          this.select_init_unrun();
        }else{
          this.list_strategy_unrun = [];
        }
      },
      computed:{
        computed_client(){   //vux要监听对象
          return this.get_client()
        },
        computed_contract(){
          return this.get_contract()
        },
        computed_list_strategy_run(){
          return this.get_list_strategy_run()
        },
        computed_list_strategy_unrun(){
          return this.get_list_strategy_unrun()
        },
        computed_data_group_id_run(){
          return this.get_data_group_id_run()
        },
        computed_data_group_id_unrun(){
          return this.get_data_group_id_unrun()
        },
        client_and_contract(){   //如果client和contract都发生改变执行
          const  { clientSelected,contractSelected} = this;
          return {
            clientSelected,
            contractSelected
          }
        },
        computed_run_select_Ids(){
          return this.get_run_select_Ids()
        },
        computed_unrun_select_Ids(){
          return this.get_unrun_select_Ids()
        },
      },
      watch:{
        computed_client(){
          this.clientSelected = this.get_client();
        },
        computed_contract(){
          this.contractSelected = this.get_contract()
        },
        computed_list_strategy_run(){
          this.list_strategy_run = this.get_list_strategy_run();
          this.updateRunGroup_idEvent()
          //初始化策略分组
          this.select_init_run();
          this.run_selection();
        },
        computed_list_strategy_unrun(){
          this.list_strategy_unrun = this.get_list_strategy_unrun();
          this.select_init_unrun();
          this.unrun_selection();
        },
        computed_data_group_id_run(){
          this.data_group_id_run = this.get_data_group_id_run();
        },
        computed_data_group_id_unrun(){
          this.data_group_id_unrun = this.get_data_group_id_unrun();
        },
        client_and_contract(){ //获取到用户id和合约后执行的方法
          if(this.clientSelected !== '' && this.contractSelected !==''  ){
            this.get_ListStrategy2();
          }
        },
        run_status(){
          this.set_run_status(this.run_status);
          if(this.run_status){
            this.$nextTick(function() {
              this.$refs.strategy_Table_run.doLayout()
            });
          }else {
            this.$nextTick(function() {
              this.$refs.strategy_Table_unrun.doLayout()
            });
          }
        },
        computed_run_select_Ids(){
          this.run_select_Ids = this.get_run_select_Ids();
          this.run_selection();
          this.select_strategy_run();
        },
        computed_unrun_select_Ids(){
          this.unrun_select_Ids = this.get_unrun_select_Ids();
          this.unrun_selection();
          this.select_strategy_unrun();
        },
      }
    }
</script>

<style scoped lang="less">
  .trade_bottom{
    .m_strategy{
      height: 48px;
      font-size: 14px;
      display: flex;
      .group_item{
        user-select: none;
        display:inline-block;
        a{
          margin: 0 6px;
          padding: 6px 20px;
          border-radius: 2px;
        }
        .system_choseNav{
          border-color: #84A2E0;
          background-color: #84A2E0;
          color:  #FFFFFF;
        }
      }
      .ms_buy{
        margin-top: 14px;
        width: 50%;
        display: flex;
        .ms_1{
          margin-right: 48px;
          .lb_1{
            margin-left: 16px;
            cursor: pointer;
          }
          .lb_2{
            margin-left: 13px;
          }
        }
      }
      .ms_sell{
        width: 50%;
        display: flex;
        .group_item{

          margin-top: 15px;
        }
        .ms_other{
          margin-left: 100px;
          margin-top: 8px;
        }
      }

    }
    .m_table{
      /deep/ .elx-table .elx-body--column.col--center{
        height: 24px;
      }
      /deep/ .elx-table .elx-table--header-wrapper .elx-table--header-border-line ,/deep/ .elx-table .elx-table--border-line{
        border: 0;
      }
    }
  }
</style>
